param(
    $sub = "build",
    $exec = "hello"
)

if ($sub -eq "run") {
    build
    &"./ninja/$exec.exe"
}
elseif ($sub -eq "build") {
    build
}

function build_inner {
    Set-Location ./ninja
    ninja
    Set-Location ..
}

function build {
    if (Test-Path './ninja/build.ninja') {
        build_inner
    }
    else {
        cmake -G "Ninja" -B ninja
        cmd /c 'mklink /h compile_commands.json .\ninja\compile_commands.json'
        build_inner
    }
}

